package demo.base;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.xml.internal.ws.util.StringUtils;

public class MyIOHandler extends IoHandlerAdapter {

	private static final Logger log = LoggerFactory.getLogger(MyIOHandler.class);

	@Override
	public void messageReceived(IoSession session, Object message) throws Exception {
		String str = message.toString();
		log.info("receive msg [" + str + "]");
		
		String resp = StringUtils.capitalize(str);
		session.write(resp);
		
		if (str.endsWith("quit")) {
			session.close(true);
			return;
		}
	}
}
